cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
cmake_policy(SET CMP0054 NEW)

set(PROJECT_VERSION 0.2.0)
project(sv2gimbal VERSION ${PROJECT_VERSION} LANGUAGES CXX)

add_definitions(-DAPI_EXPORTS)
set(CMAKE_BUILD_TYPE "Release")

find_package(SpireMS REQUIRED)
include_directories(${SpireMS_INCLUDE_DIRS})

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(
  ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/IOs/serial/include
  ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src/FIFO
  ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src/G1
  ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src/AT10
  ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src/Q10f
  ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src/GX40
  ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src/SU17-G
  ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src
  ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl
)

# Public header
set(
  public_HEADS
  include/sv2_gimbal.h
  include/sv2_gimbal_sms.h
)

# Gimbal Sources
set(serial_SRCS
  gimbal_ctrl/IOs/serial/src/serial.cc
)
list(APPEND serial_SRCS gimbal_ctrl/IOs/serial/src/impl/unix.cc)
list(APPEND serial_SRCS gimbal_ctrl/IOs/serial/src/impl/list_ports/list_ports_linux.cc)

set(driver_SRCS
  gimbal_ctrl/driver/src/FIFO/Ring_Fifo.cpp
)
file(GLOB DRV_LIB_FILES ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src/G1/*.cpp)
list(APPEND driver_SRCS ${DRV_LIB_FILES})
file(GLOB DRV_LIB_FILES ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src/AT10/*.cpp)
list(APPEND driver_SRCS ${DRV_LIB_FILES})
file(GLOB DRV_LIB_FILES ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src/Q10f/*.cpp)
list(APPEND driver_SRCS ${DRV_LIB_FILES})
file(GLOB DRV_LIB_FILES ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src/GX40/*.cpp)
list(APPEND driver_SRCS ${DRV_LIB_FILES})
file(GLOB DRV_LIB_FILES ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src/SU17-G/*.cpp)
list(APPEND driver_SRCS ${DRV_LIB_FILES})
file(GLOB DRV_LIB_FILES ${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl/driver/src/*.cpp)
list(APPEND driver_SRCS ${DRV_LIB_FILES})

set(gimbal_SRCS
  gimbal_ctrl/sv2_gimbal.cpp
  gimbal_ctrl/sv2_gimbal_io.hpp
  src/sv2_gimbal_sms.cpp
)

# Gimbal Lib
add_library(sv2_gimbal SHARED ${serial_SRCS} ${driver_SRCS} ${gimbal_SRCS})
target_link_libraries(sv2_gimbal rt pthread)



add_executable(SV2GimbalDemo SV2GimbalDemo.cpp)
target_link_libraries(SV2GimbalDemo sv2_gimbal ${SpireMS_LIBS})


